/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software Foundation,
 *    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */

package JET.Frames.materialsframe;

import JET.Centers.ControlCenter;
import JET.Scene;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JTable;
import javax.swing.event.MouseInputListener;

/**
 *
 * @author 057Ry
 */
public class MaterialsTableMouseInputListener implements MouseInputListener{

    MaterialsDialog materialsDialog;
    static final ControlCenter CC = ControlCenter.getInstance();
    private Scene scene;

    public MaterialsTableMouseInputListener(MaterialsDialog md) {
        materialsDialog = md;
    }

    public void setScene(Scene s) {
        scene = s;
    }
    private void respondToSelection(MouseEvent e)
    {
        JTable table = (JTable)e.getSource();
        int r = table.rowAtPoint(e.getPoint());
        int c = table.columnAtPoint(e.getPoint());

        if (c>=0 && c<scene.getJETContext().materialNames.length &&
            r>=0 && r<scene.getJETContext().materialNames.length)
        {
            materialsDialog.setMaterial1Name(scene.getJETContext().materialNames[r]);
            materialsDialog.setMaterial2Name(scene.getJETContext().materialNames[c]);
            materialsDialog.setMaterial1Index(r);
            materialsDialog.setMaterial2Index(c);
            materialsDialog.setBounceValue(scene.getJETContext().materials[r][c].elasticity);
            materialsDialog.setFrictionValue(scene.getJETContext().materials[r][c].friction);
            materialsDialog.setCollisionCheckBoxSelected(scene.getJETContext().materials[r][c].collide);
        }
    }
    public void mouseClicked(MouseEvent e) {}

    public void mousePressed(MouseEvent e) {
        respondToSelection(e);
    }

    public void mouseReleased(MouseEvent e) {}

    public void mouseEntered(MouseEvent e) {}

    public void mouseExited(MouseEvent e) {}

    public void mouseDragged(MouseEvent e) {
        respondToSelection(e);
    }

    public void mouseMoved(MouseEvent e) {}

}
